package com.cloud.adrian.novel.book.controller.inner;

import com.cloud.adrian.novel.book.dto.req.*;
import com.cloud.adrian.novel.book.dto.resp.BookChapterContentRespDto;
import com.cloud.adrian.novel.book.dto.resp.BookChapterRespDto;
import com.cloud.adrian.novel.book.dto.resp.BookEsRespDto;
import com.cloud.adrian.novel.book.dto.resp.BookInfoRespDto;
import com.cloud.adrian.novel.book.service.BookService;
import com.cloud.adrian.novel.common.constant.ApiRouterConstants;
import com.cloud.adrian.novel.common.resp.PageRespDto;
import com.cloud.adrian.novel.common.resp.RestResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小说微服务内部调用接口
 * @Author: xiangguiliang
 * @version: 1.0
 * @since: 2024/05/20
 */
@Tag(name = "InnerBookController", description = "小说微服务内部调用接口")
@RestController
@RequestMapping(ApiRouterConstants.API_INNER_BOOK_URL_PREFIX)
@RequiredArgsConstructor
public class InnerBookController {
    private final BookService bookService;

    /**
     * 首页推荐批量查询小说信息
     */
    @Operation(description = "批量查询小说信息")
    @PostMapping("listBookInfoByIds")
    public RestResp<List<BookInfoRespDto>> listBookInfoByIds(@RequestBody List<Long> bookIds) {
        return bookService.listBookInfoByIds(bookIds);
    }

    /**
     * 用户发表评论接口
     */
    @Operation(description = "发表评论接口")
    @PostMapping("publishComment")
    public RestResp<Void> publishComment(@Valid @RequestBody BookCommentReqDto dto) {
        return bookService.saveComment(dto);
    }

    /**
     * 用户修改小说评论接口
     */
    @Operation(description = "修改评论接口")
    @PostMapping("updateComment")
    public RestResp<Void> updateComment(@Valid @RequestBody BookCommentReqDto dto) {
        return bookService.updateComment(dto);
    }

    /**
     * 用户删除小说评论接口
     */
    @Operation
    @PostMapping("deleteComment")
    public RestResp<Void> deleteComment(@Valid @RequestBody BookCommentReqDto dto) {
        return bookService.deleteComment(dto);
    }

    /**
     * 查询下一批保存到es的小说列表
     */
    @Operation(description = "查询下一批保存到es的小说列表")
    @PostMapping("listNextEsBooks")
    public RestResp<List<BookEsRespDto>> listNextEsBooks(
            @Parameter(description = "已查询的最大小说id") @RequestBody Long maxBookId) {
        return bookService.listNextEsBooks(maxBookId);
    }

    @Operation(description = "发布小说")
    @PostMapping("publishBook")
    public RestResp<Void> publishBook(@Valid @RequestBody BookAddReqDto dto) {
        return bookService.publishBook(dto);
    }

    @Operation(description = "发布小说列表查询")
    @PostMapping("listPublishBooks")
    public RestResp<PageRespDto<BookInfoRespDto>> listPublishBooks(@RequestBody BookPageReqDto dto) {
        return bookService.listAuthorBooks(dto);
    }

    @Operation(description = "发布小说章节")
    @PostMapping("publishBookChapters")
    public RestResp<Void> publishBookChapters(@Valid @RequestBody ChapterAddReqDto dto) {
        return bookService.publishBookChapters(dto);
    }

    @Operation(description = "查询小说章节列表")
    @PostMapping("listPublishBookChapters")
    public RestResp<PageRespDto<BookChapterRespDto>> listPublishBookChapters(
            @RequestBody ChapterPageReqDto dto) {
        return bookService.listBookChapters(dto);
    }

    @Operation(description = "查询小说章节内容")
    @PostMapping("getChapterContent")
    public RestResp<BookChapterContentRespDto> getChapterContent(
            @RequestBody ChapterContentReqDto dto) {
        return bookService.getChapterContent(dto);
    }

    @Operation(description = "更新章节内容")
    @PostMapping("updateChapter")
    public RestResp<Void> updateChapter(@Valid @RequestBody ChapterAddReqDto dto) {
        return bookService.updateChapter(dto);
    }

    @Operation(description = "删除小说章节内容")
    @PostMapping("deleteChapter")
    public RestResp<Void> deleteChapter(@Valid @RequestBody ChapterContentReqDto dto) {
        return bookService.deleteChapter(dto);
    }

    @Operation(description = "查询小说内容")
    @PostMapping("selectBookById")
    public RestResp<BookEsRespDto> selectBookById(@RequestBody Long bookId) {
        return bookService.selectEsBookById(bookId);
    }
}















